package com.ruoyi.system.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    // 交换机名称
    public static final String ORDER_CHANGE_NAME = "notice_exchange";
    // 队列名称
    public static final String USER_QUEUE = "user.notice.queue";
    public static final String MERCHANT_QUEUE = "merchant.notice.queue";
//    public static final String ALL_QUEUE = "all.notice.queue";
    // 声明交换机
    @Bean
    public Exchange noticeExchange() {
        return  ExchangeBuilder.directExchange(ORDER_CHANGE_NAME).durable(true).build();
    }
    // 声明队列
    @Bean
    public Queue userQueue() {
        return QueueBuilder.durable(USER_QUEUE).build();
    }
    @Bean
    public Queue merchantQueue() {
        return QueueBuilder.durable(MERCHANT_QUEUE).build();
    }
//    @Bean
//    public Queue allQueue() {
//        return QueueBuilder.durable(ALL_QUEUE).build();
//    }
    // 绑定队列和交换机
    @Bean
    public Binding bindingUser() {
        return
                BindingBuilder.bind(userQueue()).to(noticeExchange()).with("notice.user").noargs();
    }
    @Bean
    public Binding bindingMerchant() {
        return
                BindingBuilder.bind(merchantQueue()).to(noticeExchange()).with("notice.merchant").noargs();
    }
//    @Bean
//    public Binding bindingAll() {
//        return
//                BindingBuilder.bind(allQueue()).to(noticeExchange()).with("notice.*").noargs();
//    }
}